package com.chat.datea.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.chat.datea.R;
import com.chat.datea.bean.JumpEntity;
import com.chat.datea.utils.cache.MyConfig;

import java.util.List;

/**
 * Created by dllo on 15/10/23.
 */
public class FindFragment_Jump_ListView_Adapter extends BaseAdapter {
    private List<JumpEntity.ResultEntity.ItemsEntity> data;
    private JumpEntity jumpEntity;
    private Context mContext;

    public FindFragment_Jump_ListView_Adapter(Context c, JumpEntity entity){
        mContext = c;
        jumpEntity = entity;
        data = jumpEntity.getResult().getItems();

    }
    @Override
    public int getCount() {
        return data != null && data.size() > 0 ? data.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return data != null && data.size() > 0 ? data.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null){
            holder = new ViewHolder();
            //通过布局加载器来加载行布局
            convertView = LayoutInflater.from(mContext).inflate(R.layout.fragment_find_songlist_jump_item, null);
            //初始化行布局里的控件
            holder.find_Jump_Title = (TextView) convertView.findViewById(R.id.find_Jump_Title);
            holder.find_Jump_Name = (TextView) convertView.findViewById(R.id.find_Jump_Name);
            holder.find_Jump_Image = (ImageView) convertView.findViewById(R.id.find_Jump_Image);
            //添加标签
            convertView.setTag(holder);
        }
        else {
            holder = (ViewHolder) convertView.getTag();
        }
        final JumpEntity.ResultEntity.ItemsEntity itemsEntity = (JumpEntity.ResultEntity.ItemsEntity) getItem(position);
        //设置组件
        holder.find_Jump_Title.setText(data.get(position).getSong_title());
        holder.find_Jump_Name.setText(data.get(position).getArtist_name());

        String song_id = itemsEntity.getSong_id();
        String song_title = itemsEntity.getSong_title();
        MyConfig.putSharePre(mContext, "song_id", "song_id", song_id);
        MyConfig.putSharePre(mContext, "song_title", "song_title", song_title);
        return convertView;
    }
    public class ViewHolder{
        private TextView find_Jump_Title, find_Jump_Name;
        private ImageView find_Jump_Image;

    }
}
